//
//  DiscoveryController.m
//  soccer
//
//  Created by 上官千城 on 15/9/7.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "DiscoveryController.h"

@interface DiscoveryController ()

@end

@implementation DiscoveryController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor grayColor];
    self.navigationItem.title = @"发现";
    
    UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    view.image = [UIImage imageNamed:@"圈子占位符@2x"];
    [self.view addSubview:view];
    
//创建tableview
    self.discoverTab = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - self.navigationController.navigationBar.frame.size.height - self.tabBarController.tabBar.bounds.size.height) style:UITableViewStyleGrouped];
//    self.discoverTab.backgroundColor = [UIColor whiteColor];
    self.discoverTab.delegate = self;
    self.discoverTab.dataSource = self;
    [self.view addSubview:self.discoverTab];
    
    
    [self getMessage];
//创建头部视图
    self.heardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT *1/3)];
    self.heardView.backgroundColor = [UIColor whiteColor];
    self.discoverTab.tableHeaderView = self.heardView;
    self.heardScrool = [[MyScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, self.heardView.frame.size.height)];
    self.heardScrool.backgroundColor = [UIColor whiteColor];
    [self.heardView addSubview:self.heardScrool];
    
   
    
    
    
}




-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        
        return 10;
    } else {
    
        return 30;
    }

}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        return @"您可能喜欢的";
    } else {
    
        return @"最新资讯";
    }


}

-(void)getMessage
{
    self.myArray = [NSMutableArray array];
    
[AFN AFNGetData:@"http://lolbox.oss.aliyuncs.com/json/v3/news/banner.json" andBlock:^(id respondes) {
//    NSLog(@"responds == %@",respondes);
    
    NSMutableArray *array = respondes;
    
    for (NSMutableDictionary *dic in array) {
        self.scroll = [[ScrollModel alloc] init];
        self.scroll.img = [dic objectForKey:@"img"];
        self.scroll.myId = [dic objectForKey:@"id"];
        [self.myArray addObject:self.scroll];
               
        
    }

    if (self.myArray.count != 0) {
        
        [self.heardScrool setImages:self.myArray];
    }

    
    
}];


}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        static NSString *scrollId = @"scrollCell";
        DiscoverCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:scrollId];
        if (cell == nil) {
            
            cell = [[DiscoverCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:scrollId];
            
        }
        
        NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"team1@2x.png",@"未标题-1_03@2x.png",@"未标题-1_06@2x.png",@"未标题-1_09@2x.png",@"未标题-1_22@2x.png",@"501@2x.png",@"506@2x.png",@"513@2x.png", nil];
        
        cell.interestImage = arr;
        return cell;
    } else if (indexPath.section == 0 && indexPath.row == 1) {
    
    static NSString *buttonId = @"buttonCell";
        DiscoverCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:buttonId];
        if (cell == nil) {
            
            cell = [[DiscoverCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:buttonId];
            
        }

    
        return cell;
    }
    
    
static NSString *identifier = @"discoverCell";
    DiscoverCell *discoCell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (discoCell == nil) {
        discoCell = [[DiscoverCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
    }
    
//    discoCell.backgroundColor = [UIColor whiteColor];
//    discoCell.textLabel.text = @"1111";
    
    return discoCell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return 2;
    }else {
    
        return 20;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        return 80;
    } else if (indexPath.section == 0 && indexPath.row == 1) {
        return 160;
    }
    return 100;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];


}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
